//
//  PGScrollView.m
//  PhotographicGuide
//
//  Created by indream on 13-2-13.
//  Copyright (c) 2013年 indream. All rights reserved.
//

#import "PGScrollView.h"

@implementation PGScrollView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    if(!self.isDragging){
        [self.nextResponder touchesBegan:touches withEvent:event];
    }
    [super touchesBegan:touches withEvent:event];
    if([[touches anyObject] tapCount] == 2){
        CGPoint point = [[touches anyObject] locationInView:self];
        if(self.zoomScale!=1){
            [self zoomToPointInRootView:point atScale:1];
        }else{
            [self zoomToPointInRootView:point atScale:2];
        }
    }
}
- (void)zoomToPointInRootView:(CGPoint)center atScale:(float)scale {
    CGRect zoomRect;
    zoomRect.size.height = self.frame.size.height / scale;
    zoomRect.size.width  = self.frame.size.width  / scale;
    zoomRect.origin.x = center.x - (zoomRect.size.width  / 2.0);
    zoomRect.origin.y = center.y - (zoomRect.size.height / 2.0);
    [self zoomToRect:zoomRect animated:YES];
    
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
    if(!self.isDragging){
        [self.nextResponder touchesEnded:touches withEvent:event];
    }
    [super touchesEnded:touches withEvent:event];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
